package com.lc.fbtp.draftmsg.parser.ccm;

import java.io.IOException;
import java.io.InputStream;

import org.junit.Assert;
import org.junit.Test;

import com.lc.fbtp.draftmsg.api.paper.DraftInfo;
import com.lc.fbtp.draftmsg.core.parse.paper.PaperParser;
import com.lc.fbtp.draftmsg.core.utils.SHA256;

public class CCM010Test_1 {

	@Test
	public void testParse(){
//		String msg = "{H:00110000000000010000010000120170426103000CPR.001.005         A1234B1234C1234D123400000000000000000000U3N00006447A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4         }\r\n";
		InputStream input = this.getClass().getResourceAsStream("/ccm/CCM.010.001.1.xml");
		byte[] b = null;
		try {
			b = new byte[input.available()];
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			input.read(b);
		} catch (IOException e1) {
			e1.printStackTrace();
		} finally {
			try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		PaperParser parser = PaperParser.getInstance();
		DraftInfo draftInfo = parser.parse(b);
		Assert.assertNotNull(draftInfo.getMsgBody());
		String encryStr = SHA256.encry(draftInfo.getMsgBodyStr());
		Assert.assertTrue("报文体SHA-256加密结果为["+ encryStr +"],报文校验和为["+ draftInfo.getMsgHeader().getBodyChksum() +"],不匹配", encryStr.equals(draftInfo.getMsgHeader().getBodyChksum()));
		//TODO 报文schema校验
		//TODO 报文加签校验
//		System.out.println(draftInfo.toJsonString());
		System.out.println(draftInfo.getMsgHeader().getBodyChksum());
		
	}
}
